/**
 *@author readkid
 *@dependence jquery 1.2
 *@since 2010/1/15
 *@version 1.0
 */ 
(function () {
	//using namespace $.suning;
	$.suning || ($.suning = {});
	//Extends
	$.suning.extend = function (subClass, superClass) {
		var F = function() {};
		F.prototype = superClass.prototype;
		subClass.prototype = new F();
		superClass.prototype.constructor = superClass;
		subClass.prototype.constructor = subClass;
		subClass.base = superClass.prototype;
	}
})();
var scrolltotop={
	//startline: Integer. Number of pixels from top of doc scrollbar is scrolled before showing control
	//scrollto: Keyword (Integer, or "Scroll_to_Element_ID"). How far to scroll document up when control is clicked on (0=top).
	setting: {startline:100, scrollto: 0, scrollduration:1000, fadeduration:[500, 100]},
	controlHTML: '<img src="themes/goldlv/images/backtotop.gif" style="width:20px; height:63px" />', //HTML for control, which is auto wrapped in DIV w/ ID="topcontrol"
	controlattrs: {offsetx:5, offsety:5}, //offset of control relative to right/ bottom of window corner
	anchorkeyword: '#top', //Enter href value of HTML anchors on the page that should also act as "Scroll Up" links

	state: {isvisible:false, shouldvisible:false},

	scrollup:function(){
		if (!this.cssfixedsupport) //if control is positioned using JavaScript
			this.$control.css({opacity:0}) //hide control immediately after clicking it
		var dest=isNaN(this.setting.scrollto)? this.setting.scrollto : parseInt(this.setting.scrollto)
		if (typeof dest=="string" && jQuery('#'+dest).length==1) //check element set by string exists
			dest=jQuery('#'+dest).offset().top
		else
			dest=0
		this.$body.animate({scrollTop: dest}, this.setting.scrollduration);
	},

	keepfixed:function(){
		var $window=jQuery(window)
		var controlx=$window.scrollLeft() + $window.width() - this.$control.width() - this.controlattrs.offsetx
		var controly=$window.scrollTop() + $window.height() - this.$control.height() - this.controlattrs.offsety
		this.$control.css({left:controlx+'px', top:controly+'px'})
		if(controlx + this.$control.width() > 980){
  controlx = 980 - this.$control.width()
}
	},

	togglecontrol:function(){
		var scrolltop=jQuery(window).scrollTop()
		if (!this.cssfixedsupport)
			this.keepfixed()
		this.state.shouldvisible=(scrolltop>=this.setting.startline)? true : false
		if (this.state.shouldvisible && !this.state.isvisible){
			this.$control.stop().animate({opacity:1}, this.setting.fadeduration[0])
			this.state.isvisible=true
		}
		else if (this.state.shouldvisible==false && this.state.isvisible){
			this.$control.stop().animate({opacity:0}, this.setting.fadeduration[1])
			this.state.isvisible=false
		}
	},
	
	init:function(){
		jQuery(document).ready(function($){
			var mainobj=scrolltotop
			var iebrws=document.all
			mainobj.cssfixedsupport=!iebrws || iebrws && document.compatMode=="CSS1Compat" && window.XMLHttpRequest //not IE or IE7+ browsers in standards mode
			mainobj.$body=(window.opera)? (document.compatMode=="CSS1Compat"? $('html') : $('body')) : $('html,body')
			mainobj.$control=$('<div id="topcontrol">'+mainobj.controlHTML+'</div>')
				.css({position:mainobj.cssfixedsupport? 'fixed' : 'absolute', bottom:mainobj.controlattrs.offsety, right:mainobj.controlattrs.offsetx, opacity:0, cursor:'pointer'})
				.attr({title:'Scroll Back to Top'})
				.click(function(){mainobj.scrollup(); return false})
				.appendTo('body')
			if (document.all && !window.XMLHttpRequest && mainobj.$control.text()!='') //loose check for IE6 and below, plus whether control contains any text
				mainobj.$control.css({width:mainobj.$control.width()}) //IE6- seems to require an explicit width on a DIV containing text
			mainobj.togglecontrol()
			$('a[href="' + mainobj.anchorkeyword +'"]').click(function(){
				mainobj.scrollup()
				return false
			})
			$(window).bind('scroll resize', function(e){
				mainobj.togglecontrol()
			})
		})
	}
}

scrolltotop.init()
//SideNav
$.suning.MenuNav = function() {
	var timer;
	if($("#SideNav").css("display") == "none"){
		$(".sn_Menu").hover(function(){
			clearInterval(timer);					 
			$("#SideNav").css("display","block");	
			$(this).find(".sn_Menuicon").addClass("on");
						
			$("#SideNav").find("dl").each(function(i){
				$(this).mouseover(function() {
					navshow(i);
				});				   
			});
			
			function navshow(i){
				$("#SideNav").find(".icon").removeClass('on').eq(i).addClass("on");
				$("#SideNav").find(".sidenavchild").hide().eq(i).show();
			};
			
		},function(){
			timer = setInterval(function(){
				$("#SideNav").css("display","none");
			},1);
			$("#SideNav").find(".icon").removeClass('on');	
			$(this).find(".sn_Menuicon").removeClass("on");
			$(this).find(".sidenavchild").hide();
		});
		
	}else{	
		$("#SideNav").find("dl").each(function(i){
			$(this).mouseover(function(){
				$(this).find(".icon").addClass("on");	
				$(this).find(".sidenavchild").css("display","block");
			}).mouseout(function(){
				$(this).find(".icon").removeClass("on");	
				$(this).find(".sidenavchild").css("display","none");				
			})										   
		});		
	}
	
} 


/* tab */
$.suning.TabClick = function(id,showId){
	$("#"+id).find("li").each(function(i){
		$(this).find("a").mouseover(function(e){
			$(this).addClass("on").parent().siblings().find("a").removeClass("on");	
			$("."+showId).hide().eq(i).show();
		})
	});	
}


$.suning.IndexTab = function(){
	var index = 0 ;
	var timer,settime;
	
	$("#sn_sevice").hover(function(){
		$("#sn_seviceMore").show();						   
	},function(){
		$("#sn_seviceMore").hide();
	});
	
	$("#basket").hover(function(){
		$("#basketShow").show();
	},function(){
		$("#basketShow").hide();
	});
	
	var len = $("#Package").find("li").length ;
	$("#Package").find(".Package ul").width(576*len);
	$("#Package").find(".Packageright a").click(function(){
		if(index>=len-1){
			return false;
		}												 
		index ++ ;												 
		$("#Package").find(".Package ul").stop().animate({"marginLeft":-576*index},300);
	});
	
	$("#Package").find(".Packageleft a").click(function(){
		if(index<=0){
			return false;
		}												 
		index -- ;												 
		$("#Package").find(".Package ul").stop().animate({"marginLeft":-576*index},300);
	});
	
	$("#Package").hover(function(){
		 clearInterval(timer);
	},function(){
		timer = setInterval(function(){
		   if(index==len-1){index=-1;}						 
		   index++;						
		   $("#Package").find(".Package ul").stop().animate({"marginLeft":-576*index},300);		
		} , 4000);
	}).trigger("mouseleave");
	
	
	$("#promoreTab").find("a").click(function(e){
		e.preventDefault();									  
		index  =  $("#promoreTab a").index(this);	
		scrollAuto(index);
	});	
	
	$("#promoreTab").hover(function(){
		 clearInterval(timer);
	},function(){
		timer = setInterval(function(){
		   scrollAuto(index);			
		   index++;
		   if(index==7){index=0;}
	    } , 3600);
	}).trigger("mouseleave");
	
	function scrollAuto(index){
		$("#promoreTab").find("a").eq(index).addClass("on").siblings().removeClass("on");	
		$("#promoreTabList li").hide().eq(index).show();		
	};
}



var snTopList = function(tabId,id){
	var btn = $('#'+id).find('li');
	var len = btn.length ;
	return{
		init:function(){
			var that = this ;
			$("#"+tabId).find("a").mouseover(function(e){
				e.preventDefault();								 
				$(this).addClass("on").parent().siblings().find("a").removeClass("on");
				var href = $(this).attr("href");
				$("#"+id).html("<div class='snToploading'></div>");
				$.post(href,function(data){
					$("#"+id).html(data);	
					snTopList('indexTab01','indexTopList01').changelist();	
					snTopList('indexTab02','indexTopList02').changelist();	
				});
			}).click(function(e){
				return false;
				}).bind('focus', function(){    
				if(this.blur){ 
				   this.blur();    
				}    
  			});							  
			
			that.changelist();
			
			
			$("#tabIndex01").find("li").each(function(i){
				$(this).find("a").mouseover(function(){
					$(this).addClass("on").parent().siblings().find("a").removeClass('on');							 
					$(".tabIndexContent01").hide().eq(i).show();							 
				})									   
			});
			
			$("#tabIndex02").find("li").each(function(i){
				$(this).find("a").mouseover(function(){
					$(this).addClass("on").parent().siblings().find("a").removeClass('on');								 
					$(".tabIndexContent02").hide().eq(i).show();							 
				})									   
			});
			
		},
		changelist:function(){
			btn.each(function(i){
				$(this).mouseover(function(){
					$(this).addClass('on').siblings().removeClass('on');
					btn.eq(0).find(".topshow").hide();
					btn.eq(0).find(".tophide").show();
					for(var j=0;j<len;j++){
						btn.eq(j).find(".topshow").hide();
						btn.eq(j).find(".tophide").show();
					}
					$(this).find(".topshow").show();
					$(this).find(".tophide").hide();
				});
			});
		}
	}
}


$(document).ready(function() {
	$.suning.MenuNav();					   
	$.suning.TabClick('snTab','sn_noice_list');
	$.suning.IndexTab();
	snTopList('indexTab01','indexTopList01').init();	
	snTopList('indexTab02','indexTopList02').init();
		
	$(".allProItem").mouseover(function(){$(this).addClass("allProItemFocus");}).mouseout(function(){$(this).removeClass("allProItemFocus");});	
});
$(function(){
    var _titleHeight = 0;
    $('.gmg').each(function(){
        var $this = $(this),
            _height = $this.height(),
            $caption = $('.caption', $this),
            _captionHeight = $caption.outerHeight(true),
            _speed = 200;
        $this.hover(function(){
            $caption.stop().animate({
                top: _height - _captionHeight
            }, _speed);
        }, function(){
            $caption.stop().animate({
                top: _height - _titleHeight
            }, _speed);
        });
    });
});

	